import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/unit/asset_utils/asset_utils.dart';
import 'package:full_display/unit/screen/screen_utility.dart';

class SliderLightWidget extends StatefulWidget {
  final String title;
  const SliderLightWidget({required this.title, Key? key}) : super(key: key);

  @override
  State<SliderLightWidget> createState() => _SliderLightWidgetState();
}

class _SliderLightWidgetState extends State<SliderLightWidget> {
  double sliderValue = 0.0;
  String sliderText = "还没操作";

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          padding: EdgeInsets.only(left: 20.0.W, top: 20.0.H),
          child: Text(
            widget.title,
            style: StandardTextStyle.textWhite12Op75Style,
          ),
        ),
        Container(
          padding: EdgeInsets.only(left: 30.0.W, right: 30.0.W),
          margin: EdgeInsets.only(top: 10.0.H),
          height: 56.0.H,
          decoration: const BoxDecoration(
            color: ColorPlate.backgroundOpacity5,
            borderRadius: BorderRadius.all(Radius.circular(12.0)),
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Image.asset(
                  height: 24.0.H,
                  width: 24.0.W,
                  AssetUtils.getAsset2Image("icon_light")),
              Container(
                padding: EdgeInsets.only(top: 10.0.H),
                height: 30,
                width: 252.0.W,
                child: _slider(),
              ),
              Image.asset(
                  height: 24.0.H,
                  width: 24.0.W,
                  AssetUtils.getAsset2Image("icon_light")),
            ],
          ),
        ),
      ],
    );
  }

  Slider _slider() {
    return Slider(
      value: sliderValue,
      activeColor: ColorPlate.sub_blue,
      inactiveColor: ColorPlate.backgroundOpacity20,
      max: 100,
      onChanged: (value) {
        print("onChanged : $value");
        updateSlider(value, "onChanged : $value");
      },
      onChangeStart: (value) {
        print("onChangeStart : $value");
        updateSlider(value, "onChangeStart : $value");
      },
      onChangeEnd: (value) {
        print("onChangeEnd : $value");
        updateSlider(value, "onChangeEnd : $value");
      },
    );
  }

  void updateSlider(value, text) {
    print("onChangeEnd : $value");
    sliderValue = value;
    sliderText = text;

    setState(() {});
  }
}
